/**
 * 
 */
package com.gwcloud.leetcode.interview100;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @ClassName   : Leetcode0179 
 * @author      : ganwei 
 * @date        : 2020年5月28日
 * @Description : Leetcode0179 最大数
 */
public class Leetcode0179 {
    /**
     * -解题思路，
     */
	public String largestNumber(int[] nums) {
        
        String[] asStrs = new String[nums.length];
        for (int i = 0; i < nums.length; i++) {
            asStrs[i] = String.valueOf(nums[i]);
        }

        
        Arrays.sort(asStrs, new LargerNumberComparator());


        if (asStrs[0].equals("0")) {
            return "0";
        }

        String largestNumberStr = new String();
        for (String numAsStr : asStrs) {
            largestNumberStr += numAsStr;
        }

        return largestNumberStr;
    }
	
    public class LargerNumberComparator implements Comparator<String> {
        @Override
        public int compare(String a, String b) {
            String order1 = a + b;
            String order2 = b + a;
           return order2.compareTo(order1);
        }
    }

    /**
     * -主函数
     */
    public static void main(String[] args){
    	System.out.println("392".compareTo("3911"));
    }
}
